package com.wxtt.android.receiver;

import com.fast.dev.frame.utils.LogUtils;
import com.fast.dev.frame.utils.StringUtils;
import com.wxtt.android.config.SpConfig;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 说明：处理消息
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2016/3/2 14:22
 * <p/>
 * 版本：verson 1.0
 */
public class HandlerPushMessage {

    private static HandlerPushMessage sHandlerPushMessage;

    private HandlerPushMessage(){}

    public static synchronized HandlerPushMessage get(){
        if (sHandlerPushMessage == null){
            sHandlerPushMessage = new HandlerPushMessage();
        }
        return sHandlerPushMessage;
    }


    interface PushJsonKey{
        String welcome = "welcome";
    }

    /**
     * 说明：处理消息
     * @param message
     */
    public void message(String message){
        try {
            JSONObject object = new JSONObject(message);
            welcomeMessage(object);
        }catch (JSONException e){
            LogUtils.e(e);
        }
    }

    /**
     * 说明：首页欢迎内容
     * @param message
     */
    private void welcomeMessage(JSONObject message){
        String welcome = message.optString(PushJsonKey.welcome);
        if (!StringUtils.isEmpty(welcome)){
            SpConfig.setWelcomeText(welcome);
        }
    }
}
